library(MASS)
library(ggplot2)
library(Hmisc)
library(stringr)
library(stm)
library(dplyr)
library(tidyr)
library(fastDummies)
library(stringr)
library(reshape2)
library(lessR)

set.seed(44)
remove(list=ls())




### Load articles
setwd("/Users/robertchaudoin/Dropbox/Kill_Scrapes/Media coverage data/classified_from_2019_06_10/analysis_files/data/")
setwd("/Users/stephenchaudoin/Dropbox/Kill_Scrapes/Media coverage data/classified_from_2019_06_10/analysis_files/data/")
load("articles_2019_07_16.RData")

# Removing the two columns that can't be uploaded to Dataverse
d <- subset(d, select = -c(source_url, data))
save.image("/Users/stephenchaudoin/Dropbox/Kill_Scrapes/replication code for IO/phl_articleinfo_fordataverse.RData")


###
# SECTION 1: Code for STMs that has to be run pre-censoring
###
###		This section of code is what was run on the data that contained article text.


### Estimate the STMs and create data for analysis

#	Subsetting corpus, limiting only to "drug*" and before_coding == 1
d.drug <- d[ which(regexpr("drug",d$data, ignore.case = TRUE) != -1), ]
d.drugbefore <- subset(d.drug, before_coding == 1)

# STM pre-processing
d.before.processed <- textProcessor(d.drugbefore$data, metadata = d.drugbefore)
out.before <- prepDocuments(d.before.processed$documents, d.before.processed$vocab, d.before.processed$meta)

# STM estimation
# Each topic model creates a different object, depending on the particular corpus and the specification of the topic model

# Main specification, used for the main figures in the paper
#	Basic STM with K set to 75 topics
philnews.before.k75 <- stm(documents = out.before$documents, vocab = out.before$vocab, K = 75, max.em.its = 175, data = out.before$meta, init.type = "Spectral")
lt.philnews.before.k75 <- labelTopics(philnews.before.k75, n = 20, frexweight = 0.5)
lt.philnews.before.k75

# Making data table
dt.philnews.before.k75 <- make.dt(philnews.before.k75, meta = d.drugbefore)
dt.philnews.before.k75$icctopics <- dt.philnews.before.k75$Topic19
dt.philnews.before.k75$hrtopics <- dt.philnews.before.k75$Topic1 + dt.philnews.before.k75$Topic6 + dt.philnews.before.k75$Topic36 + dt.philnews.before.k75$Topic45 +
		dt.philnews.before.k75$Topic49 + dt.philnews.before.k75$Topic51 + dt.philnews.before.k75$Topic66 + dt.philnews.before.k75$Topic70 +
		dt.philnews.before.k75$Topic20 + dt.philnews.before.k75$Topic59

# Sum and mean of coverage by day
dt.philnews.before.k75.sumbyday <- dt.philnews.before.k75 %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic75,icctopics,hrtopics)), sum)

dt.philnews.before.k75.meanbyday <- dt.philnews.before.k75 %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic75,icctopics,hrtopics)), mean)

# Code that separates out Manilla Times
# Constructing the sum and mean, only for Manilla Times
dt.philnews.before.k75.mtonly <- dt.philnews.before.k75[ which(source_name_manilatimes == 1), ]
dt.philnews.before.k75.mtonly$icctopics <- dt.philnews.before.k75.mtonly$Topic19
dt.philnews.before.k75.mtonly$hrtopics <- dt.philnews.before.k75.mtonly$Topic1 + dt.philnews.before.k75.mtonly$Topic6 + dt.philnews.before.k75.mtonly$Topic36 + dt.philnews.before.k75.mtonly$Topic45 +
		dt.philnews.before.k75.mtonly$Topic49 + dt.philnews.before.k75.mtonly$Topic51 + dt.philnews.before.k75.mtonly$Topic66 + dt.philnews.before.k75.mtonly$Topic70 +
		dt.philnews.before.k75.mtonly$Topic20 + dt.philnews.before.k75.mtonly$Topic59

dt.philnews.before.k75.mtonly.sumbyday <- dt.philnews.before.k75.mtonly %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic75,icctopics,hrtopics)), sum)

dt.philnews.before.k75.mtonly.meanbyday <- dt.philnews.before.k75.mtonly %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic75,icctopics,hrtopics)), mean)

# Constructing the sum and mean, only for NO Manilla Times
dt.philnews.before.k75.nomt <- dt.philnews.before.k75[ which(source_name_manilatimes == 0), ]
dt.philnews.before.k75.nomt$icctopics <- dt.philnews.before.k75.nomt$Topic19
dt.philnews.before.k75.nomt$hrtopics <- dt.philnews.before.k75.nomt$Topic1 + dt.philnews.before.k75.nomt$Topic6 + dt.philnews.before.k75.nomt$Topic36 + dt.philnews.before.k75.nomt$Topic45 +
		dt.philnews.before.k75.nomt$Topic49 + dt.philnews.before.k75.nomt$Topic51 + dt.philnews.before.k75.nomt$Topic66 + dt.philnews.before.k75.nomt$Topic70 +
		dt.philnews.before.k75.nomt$Topic20 + dt.philnews.before.k75.nomt$Topic59

dt.philnews.before.k75.nomt.sumbyday <- dt.philnews.before.k75.nomt %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic75,icctopics,hrtopics)), sum)

dt.philnews.before.k75.nomt.meanbyday <- dt.philnews.before.k75.nomt %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic75,icctopics,hrtopics)), mean)


#	Basic STM with K set to 0, search for number of topics
set.seed(83)
philnews.before.k0 <- stm(documents = out.before$documents, vocab = out.before$vocab, K = 0, max.em.its = 175, data = out.before$meta, init.type = "Spectral")
lt.philnews.before.k0 <- labelTopics(philnews.before.k0, n = 20, frexweight = 0.5)
lt.philnews.before.k0
#	HR topics xxx   xxx (topics with ANY human rights in their words)
#	ICC topics xxx  xxx

#thoughttest <- findThoughts(philnews.before.k0, texts=d.drugbefore$data, topics=7, n=5)
#thoughttest

dt.philnews.before.k0 <- make.dt(philnews.before.k0, meta = d.drugbefore)
dt.philnews.before.k0$icctopics <- dt.philnews.before.k0$Topic34 + dt.philnews.before.k0$Topic61 + dt.philnews.before.k0$Topic73
dt.philnews.before.k0$hrtopics <- dt.philnews.before.k0$Topic7 + dt.philnews.before.k0$Topic10 + dt.philnews.before.k0$Topic17 + dt.philnews.before.k0$Topic27 + 
		dt.philnews.before.k0$Topic35 + dt.philnews.before.k0$Topic37 + dt.philnews.before.k0$Topic38 + dt.philnews.before.k0$Topic49 + dt.philnews.before.k0$Topic55 +
		dt.philnews.before.k0$Topic63 + dt.philnews.before.k0$Topic78 + dt.philnews.before.k0$Topic85

# Sum and mean of coverage by day, full k.0
dt.philnews.before.k0.sumbyday <- dt.philnews.before.k0 %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic99,icctopics,hrtopics)), sum)

dt.philnews.before.k0.meanbyday <- dt.philnews.before.k0 %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic99,icctopics,hrtopics)), mean)


### Other topic models that are estimated for analysis in the appendix

#
# Full corpus; these are used for the analysis in Appendix: "Extent of WOD Coverage"
#

# STM pre-processing
dfull.processed <- textProcessor(d$data, metadata = d)
full.out <- prepDocuments(dfull.processed$documents, dfull.processed$vocab, dfull.processed$meta)

#	Basic STM with K set to 300, full corpus
philnews.full.k300 <- stm(documents = full.out$documents, vocab = full.out$vocab, K = 300, max.em.its = 175, data = full.out$meta, init.type = "Spectral")
lt.philnews.full.k300 <- labelTopics(philnews.full.k300, n = 20, frexweight = 0.5)
lt.philnews.full.k300
dt.philnews.full.k300 <- make.dt(philnews.full.k300, meta = d)


#thoughttest <- findThoughts(philnews.full.k300, texts=d$data, topics=45, n=5)
#thoughttest

# Core WOD topics: 19, 122, 171, 190
# Peripheral Topics: 51 (prisons) 22,148 (sereno), 91 (kian), 166 (CHR), 45 (Lacson), 238 (BOC, smuggling), 269 (LDL)
# HR topics: 171, 166
dt.philnews.full.k300$corewod <- dt.philnews.full.k300$Topic19 + dt.philnews.full.k300$Topic122 + dt.philnews.full.k300$Topic171 + dt.philnews.full.k300$Topic190
dt.philnews.full.k300$hrtopics <- dt.philnews.full.k300$Topic171 + dt.philnews.full.k300$Topic166
dt.philnews.full.k300$allwod <- dt.philnews.full.k300$Topic19 + dt.philnews.full.k300$Topic122 + dt.philnews.full.k300$Topic171 + dt.philnews.full.k300$Topic190 +
	dt.philnews.full.k300$Topic51 + dt.philnews.full.k300$Topic22 + dt.philnews.full.k300$Topic148 + dt.philnews.full.k300$Topic91 +
	dt.philnews.full.k300$Topic166 + dt.philnews.full.k300$Topic45 + dt.philnews.full.k300$Topic238 + dt.philnews.full.k300$Topic269

# Sum and mean of coverage by day, full k.300
dt.philnews.full.k300.sumbyday <- dt.philnews.full.k300 %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic300,corewod,hrtopics,allwod)), sum)

dt.philnews.full.k300.meanbyday <- dt.philnews.full.k300 %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic300,corewod,hrtopics,allwod)), mean)


#	Basic STM with K set to 0, full corpus
set.seed(44)
philnews.full.k0 <- stm(documents = full.out$documents, vocab = full.out$vocab, K = 0, max.em.its = 175, data = full.out$meta, init.type = "Spectral")
lt.philnews.full.k0 <- labelTopics(philnews.full.k0, n = 20, frexweight = 0.5)
lt.philnews.full.k0
dt.philnews.full.k0 <- make.dt(philnews.full.k0, meta = d)

#thoughttest <- findThoughts(philnews.full.k0, texts=d$data, topics=53, n=5)
#thoughttest

# Core WOD topics: 9, 62
# Peripheral Topics: 15 (sereno) 49 (faeldon, ldl)
# HR topics: 62
dt.philnews.full.k0$corewod <- dt.philnews.full.k0$Topic9 + dt.philnews.full.k0$Topic62
dt.philnews.full.k0$hrtopics <- dt.philnews.full.k0$Topic62
dt.philnews.full.k0$allwod <- dt.philnews.full.k0$Topic9 + dt.philnews.full.k0$Topic62 + dt.philnews.full.k0$Topic15 + dt.philnews.full.k0$Topic49

# Sum and mean of coverage by day, full k.0
dt.philnews.full.k0.sumbyday <- dt.philnews.full.k0 %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic76,corewod,hrtopics,allwod)), sum)

dt.philnews.full.k0.meanbyday <- dt.philnews.full.k0 %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic76,corewod,hrtopics,allwod)), mean)




###
#	SECTION 2: Code for figures and other things that have to be made pre-censoring
###
# This section shows the code for making figures with example documents.  It uses the article text, so it is included here, before article texts are removed.

# Figure 1
# Example documents, shortened text
# * The first line removes some junk text.
dshort.drug <- d.drugbefore
dshort.drug$data <- str_replace_all(dshort.drug$data,"\\Q\\n\\E"," ")
dshort.drug$dataf200 <- substr(dshort.drug$data, 0, 200)
drug.thought19 <- findThoughts(philnews.before.k75, texts= dshort.drug$dataf200, topics=19, n=3)
drug.thought1 <- findThoughts(philnews.before.k75, texts= dshort.drug$dataf200, topics=1, n=3)

#pdf("/Users/robertchaudoin/Dropbox/Kill_Scrapes/Phil_Drafts/exdocs_drugbefore_k75.pdf")
par(mfrow = c(1, 2),mar = c(.5, .5, 1, .5))
plotQuote(drug.thought19$docs[[1]], width = 30, main = "ICC")
plotQuote(drug.thought1$docs[[1]], width = 30, main = "UN/HRO Spats")
dev.off()


# Figure 3 #checked
# STM coefficients
#	ICC effect, K = 75 model, drug corpus; note that these estimates are seed dependent, so resetting the seed manually here.
set.seed(83)
icceffect.drugbefore.k75 <- estimateEffect(formula = 1:75 ~ aftericc, stmobj = philnews.before.k75, metadata = d.drugbefore, uncertainty = "Global", nsims = 1000)
summary(icceffect.drugbefore.k75)

plot(icceffect.drugbefore.k75, covariate = "aftericc", model = philnews.before.k75, cov.value1 = "1", cov.value2 = "0", topics = c(19,1,70,51,6,20,59,45,36,66,49), method = "difference", labeltype = "custom", custom.labels = c("ICC","UN Spats","HRW/Roque","Mixed HR","UN CHR/HR Rep.","Tarps","Morality","Karapatan","ASEAN","HRW/EJK","CHR Budget"), xlim = c(-0.05,0.08))
#dev.off()


# Code that counts articles with human rights expressions

d$hrwords <- ifelse(regexpr("humanright",d$data, ignore.case = TRUE) != -1, 1, 0)
d$hrwordsanddrug <- ifelse(d$hrwords == 1 & d$before_coding == 1, 1, 0)
d$hrwordsandnodrug <- ifelse(d$hrwords == 1 & d$before_coding == 0, 1, 0)

d.byday.sum <- d %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(hrwords,hrwordsanddrug,hrwordsandnodrug,inclassifier)), sum)



# Code that generates objects for the STM Preprocessing pipeline analysis in Appendix G
library(preText)
# Note that preText doesn't work with R after 4.0
# Commands from basic STM preprocessing
#	dfull.processed <- textProcessor(d$data, metadata = d)
#	full.out <- prepDocuments(dfull.processed$documents, dfull.processed$vocab, dfull.processed$meta)

#http://www.mjdenny.com/getting_started_with_preText.html

randomsubset.d <- d[sample(nrow(d), 1000), ]
randomsubset.d.docsonly <- randomsubset.d$data

preprocessed_documents <- factorial_preprocessing(
    randomsubset.d.docsonly,
    use_ngrams = FALSE,
    infrequent_term_threshold = 0.001,
    verbose = FALSE)

preText_results <- preText(
    preprocessed_documents,
    dataset_name = "Random Articles",
    distance_method = "cosine",
    num_comparisons = 50,
    verbose = FALSE)

preText_score_plot(preText_results)

# Redoing STM with alternate decisions; LS preprocessing only
set.seed(44)
# STM pre-processing
# With some of these things no longer being removed in pre-processing, they need to be deleted here manually.  They're just junk from the end of some MT articles.
d.drugbefore.ls <- d.drugbefore
d.drugbefore.ls$data <- gsub("\\\\n","",d.drugbefore.ls$data)
d.drugbefore.ls$data <- gsub("2/F","",d.drugbefore.ls$data)
d.drugbefore.ls$data <- gsub("Address:  Sitio Grande Building 409 A. Soriano Avenue, Intramuros Manila 1002 Philippines Tel. : +63 (02) 524 5664 up to 67 Fax: +63 (02) 528-1729","",d.drugbefore.ls$data, fixed = TRUE)

d.before.processed.ls <- textProcessor(d.drugbefore.ls$data, metadata = d.drugbefore.ls, removestopwords = FALSE, removenumbers = FALSE, removepunctuation = FALSE)
out.before.ls <- prepDocuments(d.before.processed.ls$documents, d.before.processed.ls$vocab, d.before.processed.ls$meta)

### STM estimation

philnews.before.k75.ls <- stm(documents = out.before.ls$documents, vocab = out.before.ls$vocab, K = 75, max.em.its = 175, data = out.before.ls$meta, init.type = "Spectral")
lt.philnews.before.k75.ls <- labelTopics(philnews.before.k75.ls, n = 20, frexweight = 0.5)
lt.philnews.before.k75.ls

# Topic trend descriptions

dt.philnews.before.k75.ls <- make.dt(philnews.before.k75.ls, meta = d.drugbefore.ls)
dt.philnews.before.k75.ls$icctopics <- dt.philnews.before.k75.ls$Topic34
dt.philnews.before.k75.ls$hrtopics <- dt.philnews.before.k75.ls$Topic5 + dt.philnews.before.k75.ls$Topic8 + dt.philnews.before.k75.ls$Topic17 + dt.philnews.before.k75.ls$Topic54

# Sum and mean of coverage by day, full k.75 ls
dt.philnews.before.k75.sumbyday.ls <- dt.philnews.before.k75.ls %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic75,icctopics,hrtopics)), sum)

dt.philnews.before.k75.meanbyday.ls <- dt.philnews.before.k75.ls %>%
	group_by(pub_date_fmt) %>%
	summarise_at(vars(c(Topic1:Topic75,icctopics,hrtopics)), mean)

icceffect.drugbefore.k75.ls <- estimateEffect(formula = 1:75 ~ aftericc, stmobj = philnews.before.k75.ls, metadata = d.drugbefore.ls, uncertainty = "Global")










###
#	SECTION 3: Analysis of Replication/Dataverse Data
###

### START HERE ###

# SC code used for keeping track of things that can/can't be in the public replication files
#save.image("/Users/stephenchaudoin/Desktop/phltemp.RData")
#load("/Users/stephenchaudoin/Desktop/phltemp.RData")

#library(gdata)
#keep(		dt.philnews.before.k75.meanbyday,
#			dt.philnews.before.k75.sumbyday,
			
#			dt.philnews.before.k0.sumbyday,
#			dt.philnews.before.k0.meanbyday,

#			dt.philnews.full.k300.sumbyday,
#			dt.philnews.full.k300.meanbyday,

#			dt.philnews.full.k0.sumbyday,
#			dt.philnews.full.k0.meanbyday,

#			d.byday.sum,

#			dt.philnews.before.k75.nomt.sumbyday,
#			dt.philnews.before.k75.nomt.meanbyday,

#			dt.philnews.before.k75.mtonly.sumbyday,
#			dt.philnews.before.k75.mtonly.meanbyday,
#			sure=TRUE
#)


library(MASS)
library(ggplot2)
library(Hmisc)
library(stringr)
library(stm)
library(dplyr)
library(tidyr)
library(fastDummies)
library(stringr)
library(reshape2)
library(lessR)

set.seed(44)
remove(list=ls())

#save.image("/Users/stephenchaudoin/Dropbox/Kill_Scrapes/replication code for IO/phl_media_fordataverse.RData")
load("/Users/stephenchaudoin/Dropbox/Kill_Scrapes/replication code for IO/phl_media_fordataverse.RData")





### Figures in the main manuscript
# Figure 2, left pane #checked
# Lines for HR/ICC topics
ggplot(dt.philnews.before.k75.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"))  +
	geom_smooth(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-13"),y=0.53,label="ICC Prelim. Exam.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=0.53,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Average Prevalence") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)


# Figure 2, right pane
# Lines for specific topics #checked
ggplot(dt.philnews.before.k75.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = Topic1, col = "UN Spats, Topic 1"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic6, col = "UNCHR/HR Rep., Topic 6"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic51, col = "Mixed HR, Topic 51"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic70, col = "HRW/Roque, Topic 70"), span = 0.2, se = FALSE) + 
	annotate(geom="text",x=as.Date("2018-02-13"),y=.12,label="ICC Prelim. Exam.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=0.12,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)




### Figures in the appendix
## Figure B2 #checked
# Plot with loess lines, mean by day
ggplot(dt.philnews.full.k300.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = allwod, col = "All WOD Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = allwod, col = "All WOD Topics"))  +
	geom_smooth(aes(x = pub_date_fmt, y = corewod, col = "Core WOD Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = corewod, col = "Core WOD Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-13"),y=0.12,label="ICC Prelim. Exam.",angle=90) +
	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08"))), linetype=3)


## Figure C.1, left pane (B2 is the same as the right pane) #checked
# Plot with loess lines, sum by day
ggplot(dt.philnews.full.k300.sumbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = allwod, col = "All WOD Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = allwod, col = "All WOD Topics"))  +
	geom_smooth(aes(x = pub_date_fmt, y = corewod, col = "Core WOD Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = corewod, col = "Core WOD Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-08"),y=25,label="ICC Inv.") +
	xlab("Date") + ylab("Prevalence (sum)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08"))), linetype=3)



## Figure C2
# Top left #checked
ggplot(dt.philnews.before.k75.sumbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"))  +
	geom_smooth(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-13"),y=8,label="ICC Prelim. Exam.",angle=90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=8,label="ICC Withdr.",angle=90) +
	xlab("Date") + ylab("Prevalence (sum)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)

# Bottom left #checked
ggplot(dt.philnews.before.k75.sumbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = Topic1, col = "UN Spats Topic1"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic6, col = "UNCHR/HR Rep. Topic6"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic36, col = "ASEAN Topic36"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic45, col = "Karapatan Topic45"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic49, col = "CHR Budget Topic49"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic51, col = "Mixed Topic51"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic66, col = "HRW Topic66"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic70, col = "HRW/Roque Topic70"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic20, col = "Tarps/Stickers Topic20"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic59, col = "Morality Topic59"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic19, col = "ICC Topic19"), span = 0.2, se = FALSE) + 
	annotate(geom="text",x=as.Date("2018-02-13"),y=1.75,label="ICC Prelim. Exam.", angle=90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=1.75,label="ICC Withdrawal", angle=90) +
	xlab("Date") + ylab("Prevalence (sum)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)

# Top right #checked
ggplot(dt.philnews.before.k75.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"))  +
	geom_smooth(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-13"),y=0.53,label="ICC Prelim. Exam.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=0.53,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Average Prevalence") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)

# Bottom right #checked
ggplot(dt.philnews.before.k75.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = Topic1, col = "UN Spats Topic1"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic6, col = "UNCHR/HR Rep. Topic6"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic36, col = "ASEAN Topic36"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic45, col = "Karapatan Topic45"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic49, col = "CHR Budget Topic49"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic51, col = "Mixed Topic51"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic66, col = "HRW Topic66"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic70, col = "HRW/Roque Topic70"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic20, col = "Tarps/Stickers Topic20"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic59, col = "Morality Topic59"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic19, col = "ICC Topic19"), span = 0.2, se = FALSE) + 
	annotate(geom="text",x=as.Date("2018-02-13"),y=.12,label="ICC Prelim. Exam.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=0.12,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)


## Figure C3
# Left pane #checked
ggplot(dt.philnews.full.k0.sumbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = corewod, col = "Core WOD Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = corewod, col = "Core WOD Topics"))  +
	geom_smooth(aes(x = pub_date_fmt, y = allwod, col = "All WOD Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = allwod, col = "All WOD Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-08"),y=25,label="ICC Inv.") +
	xlab("Date") + ylab("Prevalence (sum)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08"))), linetype=3)

# Right pane #checked
ggplot(dt.philnews.full.k0.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = corewod, col = "Core WOD Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = corewod, col = "Core WOD Topics"))  +
	geom_smooth(aes(x = pub_date_fmt, y = allwod, col = "All WOD Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = allwod, col = "All WOD Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-08"),y=0.125,label="ICC Inv.") +
	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08"))), linetype=3)



## Figure C4

# Top left #checked
ggplot(dt.philnews.before.k0.sumbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"))  +
	geom_smooth(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-13"),y=7,label="ICC Prelim. Exam.", angle=90) +
	xlab("Date") + ylab("Prevalence (sum)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08"))), linetype=3)

# Bottom left #checked
ggplot(dt.philnews.before.k0.sumbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = Topic7, col = "Cebu kill. Topic7"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic10, col = "HRW/Kara. Topic10"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic17, col = "UN/UNCHR Topic17"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic27, col = "Mixed, martial Topic27"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic35, col = "Roque ap. Topic35"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic37, col = "Mixed, ASEAN Topic37"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic38, col = "CHR Budget Topic38"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic49, col = "US/Trump Topic49"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic55, col = "Tarps/Stickers Topic55"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic63, col = "EU GSP Topic63"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic78, col = "ASEAN Topic78"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic85, col = "Can./Myan. Topic85"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic34, col = "ICC Topic34"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic61, col = "ICC Topic61"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic73, col = "ICC Topic73"), span = 0.2, se = FALSE) + 
	annotate(geom="text",x=as.Date("2018-02-13"),y=1.5,label="ICC Prelim. Exam.", angle=90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=1.5,label="ICC Withdr.", angle=90) +
	xlab("Date") + ylab("Prevalence (sum)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)

# Top right #checked
ggplot(dt.philnews.before.k0.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"))  +
	geom_smooth(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-13"),y=0.5,label="ICC Prelim. Exam.", angle=90) +
	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08"))), linetype=3)

# Bottom right #checked
ggplot(dt.philnews.before.k0.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = Topic7, col = "Cebu kill. Topic7"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic10, col = "HRW/Kara. Topic10"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic17, col = "UN/UNCHR Topic17"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic27, col = "Mixed, martial Topic27"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic35, col = "Roque ap. Topic35"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic37, col = "Mixed, ASEAN Topic37"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic38, col = "CHR Budget Topic38"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic49, col = "US/Trump Topic49"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic55, col = "Tarps/Stickers Topic55"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic63, col = "EU GSP Topic63"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic78, col = "ASEAN Topic78"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic85, col = "Can./Myan. Topic85"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic34, col = "ICC Topic34"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic61, col = "ICC Topic61"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic73, col = "ICC Topic73"), span = 0.2, se = FALSE) + 
	annotate(geom="text",x=as.Date("2018-02-13"),y=0.1,label="ICC Prelim. Exam.",angle=90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=0.1,label="ICC Withdr.", angle=90) +
	xlab("Date") + ylab("Prevalence (sum)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)



## Figure D.1
# Remake of Figure 2, with the topics that don't increase after the ICC #checked
ggplot(dt.philnews.before.k75.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = Topic36, col = "ASEAN Topic36"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic45, col = "Karapatan Topic45"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic49, col = "CHR Budget Topic49"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic66, col = "HRW Topic66"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic20, col = "Tarps/Stickers Topic20"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic59, col = "Morality Topic59"), span = 0.2, se = FALSE) + 
	annotate(geom="text",x=as.Date("2018-02-13"),y=.12,label="ICC Prelim. Exam.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=0.12,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)


## Figure F.1
# checked
ggplot(dt.philnews.before.k75.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = Topic8, col = "Cabinet Turnover"), span = 0.2, se = FALSE) + 			### There are 4-5 articles here
	geom_smooth(aes(x = pub_date_fmt, y = Topic18, col = "Oplan Tokhang Resumes"), span = 0.2, se = FALSE) + 	### There are 3-4 articles here
	geom_smooth(aes(x = pub_date_fmt, y = Topic47, col = "Buy Bust"), span = 0.2, se = FALSE)				### This spike is only caused by one article on a really sparse day


## Figure F.2
# SC note to self, this came from the catholicchurchr3_2021_09_17.R file
# checked
ggplot(d.byday.sum) +
	geom_smooth(aes(x = pub_date_fmt, y = hrwordsanddrug, col = "HR + Drug"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = hrwordsanddrug, col = "HR + Drug"))  +
	geom_smooth(aes(x = pub_date_fmt, y = hrwordsandnodrug, col = "HR + No Drug"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = hrwordsandnodrug, col = "HR + No Drug"))  +
	annotate(geom="text",x=as.Date("2018-02-08"),y=13,label="ICC Inv.") +
	xlab("Date") + ylab("Number of articles") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08"))), linetype=3)


## Figure G1
# checked
ggplot(dt.philnews.full.k0.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = corewod, col = "Core WOD Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = corewod, col = "Core WOD Topics"))  +
	geom_smooth(aes(x = pub_date_fmt, y = allwod, col = "All WOD Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = allwod, col = "All WOD Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-08"),y=0.125,label="ICC Inv.") +
	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08"))), linetype=3)


## Figure G2
# Left pane #checked
ggplot(dt.philnews.before.k0.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"))  +
	geom_smooth(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-13"),y=0.5,label="ICC Prelim. Exam.", angle=90) +
	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08"))), linetype=3)

# Right pane #checked
ggplot(dt.philnews.before.k0.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = Topic7, col = "Cebu kill. Topic7"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic10, col = "HRW/Kara. Topic10"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic17, col = "UN/UNCHR Topic17"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic27, col = "Mixed, martial Topic27"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic35, col = "Roque ap. Topic35"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic37, col = "Mixed, ASEAN Topic37"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic38, col = "CHR Budget Topic38"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic49, col = "US/Trump Topic49"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic55, col = "Tarps/Stickers Topic55"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic63, col = "EU GSP Topic63"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic78, col = "ASEAN Topic78"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic85, col = "Can./Myan. Topic85"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic34, col = "ICC Topic34"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic61, col = "ICC Topic61"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic73, col = "ICC Topic73"), span = 0.2, se = FALSE) + 
	annotate(geom="text",x=as.Date("2018-02-13"),y=0.1,label="ICC Prelim. Exam.",angle=90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=0.1,label="ICC Withdr.", angle=90) +
	xlab("Date") + ylab("Prevalence (sum)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)


## Figure G4
# These figures use the output from the preText-pipeline generated topic model; not included here
#ggplot(dt.philnews.before.k75.meanbyday.ls) +
#	geom_smooth(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"), span = 0.2) + 
#	geom_point(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"))  +
#	geom_smooth(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"), span = 0.2) + 
#	geom_point(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"))  +
#	annotate(geom="text",x=as.Date("2018-02-13"),y=.6,label="ICC Prelim. Exam.",angle=90) +
#	annotate(geom="text",x=as.Date("2018-03-24"),y=.6,label="ICC Withdr.",angle=90) +
#	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
#   geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)

#ggplot(dt.philnews.before.k75.meanbyday.ls) +
#	geom_smooth(aes(x = pub_date_fmt, y = Topic5, col = "CHR/EJK Topic5"), span = 0.2, se = FALSE) + 
#	geom_smooth(aes(x = pub_date_fmt, y = Topic8, col = "Amnesty, UNCHR Topic8"), span = 0.2, se = FALSE) + 
#	geom_smooth(aes(x = pub_date_fmt, y = Topic17, col = "Trump, Canada, ASEAN Topic17"), span = 0.2, se = FALSE) + 
#	geom_smooth(aes(x = pub_date_fmt, y = Topic54, col = "Spats Topic54"), span = 0.2, se = FALSE) + 
#	geom_smooth(aes(x = pub_date_fmt, y = Topic34, col = "ICC Topic34"), span = 0.2, se = FALSE) + 
#	annotate(geom="text",x=as.Date("2018-02-13"),y=0.25,label="ICC Prelim. Exam.", angle=90) +
#	annotate(geom="text",x=as.Date("2018-03-24"),y=0.25,label="ICC Withdrawal", angle=90) +
#	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
#   geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)



## Figure G5

#ggplot(dt.philnews.before.k75.meanbyday.ls) +
#	geom_smooth(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"), span = 0.2) + 
#	geom_point(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"))  +
#	geom_smooth(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"), span = 0.2) + 
#	geom_point(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"))  +
#	annotate(geom="text",x=as.Date("2018-02-13"),y=.6,label="ICC Prelim. Exam.",angle=90) +
#	annotate(geom="text",x=as.Date("2018-03-24"),y=.6,label="ICC Withdr.",angle=90) +
#	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
#   geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)

#ggplot(dt.philnews.before.k75.meanbyday.ls) +
#	geom_smooth(aes(x = pub_date_fmt, y = Topic5, col = "CHR/EJK Topic5"), span = 0.2, se = FALSE) + 
#	geom_smooth(aes(x = pub_date_fmt, y = Topic8, col = "Amnesty, UNCHR Topic8"), span = 0.2, se = FALSE) + 
#	geom_smooth(aes(x = pub_date_fmt, y = Topic17, col = "Trump, Canada, ASEAN Topic17"), span = 0.2, se = FALSE) + 
#	geom_smooth(aes(x = pub_date_fmt, y = Topic54, col = "Spats Topic54"), span = 0.2, se = FALSE) + 
#	geom_smooth(aes(x = pub_date_fmt, y = Topic34, col = "ICC Topic34"), span = 0.2, se = FALSE) + 
#	annotate(geom="text",x=as.Date("2018-02-13"),y=0.25,label="ICC Prelim. Exam.", angle=90) +
#	annotate(geom="text",x=as.Date("2018-03-24"),y=0.25,label="ICC Withdrawal", angle=90) +
#	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
#   geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)

## Figure G6

#summary(icceffect.drugbefore.k75.ls)
#plot(icceffect.drugbefore.k75.ls, covariate = "aftericc", model = philnews.before.k75.ls, cov.value1 = "1", cov.value2 = "0", topics = c(34,54,8,17,5), method = "difference", labeltype = "custom", custom.labels = c("ICC","Spats Topic54","Amnesty, UNCHR Topic8","Trump, Canada, ASEAN Topic17","CHR/EJK Topic5"))


## Figure H1
# Top left #checked
ggplot(dt.philnews.before.k75.nomt.sumbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"))  +
	geom_smooth(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-13"),y=5.5,label="ICC Prelim. Exam.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=5.5,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Total Prevalence") + theme(legend.title = element_blank()) + ylim(0,6) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)
# Bottom left #checked
ggplot(dt.philnews.before.k75.mtonly.sumbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"))  +
	geom_smooth(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-13"),y=5.5,label="ICC Prelim. Exam.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=5.5,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Total Prevalence") + theme(legend.title = element_blank()) + ylim(0,6) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)
# Top right #checked
ggplot(dt.philnews.before.k75.nomt.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"))  +
	geom_smooth(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-13"),y=0.73,label="ICC Prelim. Exam.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=0.73,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Average Prevalence") + theme(legend.title = element_blank()) + ylim(0,1) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)
# Bottom right #checked
ggplot(dt.philnews.before.k75.mtonly.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = icctopics, col = "ICC Topic"))  +
	geom_smooth(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"), span = 0.2) + 
	geom_point(aes(x = pub_date_fmt, y = hrtopics, col = "HR Topics"))  +
	annotate(geom="text",x=as.Date("2018-02-13"),y=0.73,label="ICC Prelim. Exam.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=0.73,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Average Prevalence") + theme(legend.title = element_blank()) + ylim(0,1) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)


## Figure H2
# Top left #checked
ggplot(dt.philnews.before.k75.nomt.sumbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = Topic1, col = "UN Spats Topic1"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic6, col = "UNCHR/HR Rep. Topic6"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic36, col = "ASEAN Topic36"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic45, col = "Karapatan Topic45"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic49, col = "CHR Budget Topic49"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic51, col = "Mixed Topic51"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic66, col = "HRW Topic66"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic70, col = "HRW/Roque Topic70"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic20, col = "Tarps/Stickers Topic20"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic59, col = "Morality Topic59"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic19, col = "ICC Topic19"), span = 0.2, se = FALSE) + 
	annotate(geom="text",x=as.Date("2018-02-13"),y=1.0,label="ICC Inv.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=1.0,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Prevalence (sum)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)
# Bottom left #checked
ggplot(dt.philnews.before.k75.mtonly.sumbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = Topic1, col = "UN Spats Topic1"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic6, col = "UNCHR/HR Rep. Topic6"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic36, col = "ASEAN Topic36"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic45, col = "Karapatan Topic45"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic49, col = "CHR Budget Topic49"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic51, col = "Mixed Topic51"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic66, col = "HRW Topic66"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic70, col = "HRW/Roque Topic70"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic20, col = "Tarps/Stickers Topic20"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic59, col = "Morality Topic59"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic19, col = "ICC Topic19"), span = 0.2, se = FALSE) + 
	annotate(geom="text",x=as.Date("2018-02-13"),y=0.75,label="ICC Inv.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=0.75,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Prevalence (sum)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)
# Top right #checked
ggplot(dt.philnews.before.k75.nomt.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = Topic1, col = "UN Spats Topic1"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic6, col = "UNCHR/HR Rep. Topic6"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic51, col = "Mixed Topic51"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic70, col = "HRW/Roque Topic70"), span = 0.2, se = FALSE) + 
	annotate(geom="text",x=as.Date("2018-02-13"),y=.09,label="ICC Prelim. Exam.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=0.09,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)
# Bottom right #checked
ggplot(dt.philnews.before.k75.mtonly.meanbyday) +
	geom_smooth(aes(x = pub_date_fmt, y = Topic1, col = "UN Spats Topic1"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic6, col = "UNCHR/HR Rep. Topic6"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic51, col = "Mixed Topic51"), span = 0.2, se = FALSE) + 
	geom_smooth(aes(x = pub_date_fmt, y = Topic70, col = "HRW/Roque Topic70"), span = 0.2, se = FALSE) + 
	annotate(geom="text",x=as.Date("2018-02-13"),y=.12,label="ICC Prelim. Exam.", angle = 90) +
	annotate(geom="text",x=as.Date("2018-03-24"),y=0.12,label="ICC Withdrawal", angle = 90) +
	xlab("Date") + ylab("Prevalence (mean)") + theme(legend.title = element_blank()) +
    geom_vline(xintercept = as.numeric(as.Date(c("2018-02-08","2018-03-19"))), linetype=3)





